﻿Imports BusinessRule.DTO
Imports DatabaseAccess.DBUtility
Imports System.Text

'Copyright ?1995-2007, Camstar Systems, Inc. All Rights Reserved.
'Description:员工实体类
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:tianFW
'create Date:2019年1月5日
Public Class uLMSEmployeeBusiness
    Implements IBusiness.uLMSEmployeeIBusiness

    ''' <summary>
    ''' 插入员工信息
    ''' </summary>
    ''' <param name="dto">实体类</param>
    ''' <param name="DMLType">操作类型 1 'insert' 2'update' 3'delete'</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function IncreaseEmployee(ByVal dto As EmployeeDTO, ByVal DMLType As Integer) As Boolean Implements IBusiness.uLMSEmployeeIBusiness.IncreaseEmployee
        IncreaseEmployee = False
        Dim valueType As String = ""
        Dim pkValue As String = ""
        If DMLType = 1 Then
            valueType = "insert"
        ElseIf DMLType = 2 Then
            valueType = "update"
            pkValue = "EmployeeID"
        ElseIf DMLType = 3 Then
            valueType = "delete"
            pkValue = "EmployeeID"
        End If
        If Not DatabaseHelper.ExcuteDTO(dto, valueType, pkValue) Then
            Exit Function
        End If
        IncreaseEmployee = True
    End Function

    ''' <summary>
    ''' 根据字典传参获取人员信息
    ''' </summary>
    ''' <param name="para">传参值</param>
    ''' <returns></returns>
    ''' <remarks>用作根据分厂等查询用户信息</remarks>
    Function GetEmployeeByDic(ByVal para As Dictionary(Of String, String)) As DataTable Implements IBusiness.uLMSEmployeeIBusiness.GetEmployeeByDic
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT EM.* FROM EMPLOYEE EM ")
        If para.ContainsKey("ValueData") Then
            strsql.AppendFormat(" WHERE EM.FULLNAME LIKE '%{0}%' OR EM.FULLNAME LIKE '%{0}%'", para("ValueData"))
        ElseIf para.ContainsKey("EmployeeName") Then
            strsql.AppendFormat(" WHERE EM.EMPLOYEEName='{0}'", para("EmployeeName"))
        ElseIf para.ContainsKey("EmployeeID") Then
            strsql.AppendFormat(" WHERE EM.EMPLOYEEID='{0}'", para("EmployeeID"))
        ElseIf para.ContainsKey("CardNum") Then
            strsql.AppendFormat(" WHERE EM.CardNum='{0}'", para("CardNum"))
        End If
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function

    ''' <summary>
    ''' 获取网页菜单定义表
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetWebMeunDefinitionDT(ByVal para As Dictionary(Of String, String)) As DataTable Implements IBusiness.uLMSEmployeeIBusiness.GetWebMeunDefinitionDT
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT md.menudefinitionname,md.menudefinitionid,md.description,md.notes FROM menudefinition md")
        If para.ContainsKey("ValueData") Then
            strsql.AppendFormat(" WHERE md.menudefinitionname LIKE '%{0}%'", para("ValueData"))
        ElseIf para.ContainsKey("MenuDefinitionID") Then
            strsql.AppendFormat(" WHERE md.menudefinitionid = '{0}'", para("MenuDefinitionID"))
        End If
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function

    ''' <summary>
    ''' 获取工区信息
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetWorkCenterDT() As DataTable Implements IBusiness.uLMSEmployeeIBusiness.GetWorkCenterDT
        Dim strsql As New StringBuilder
        strsql.AppendLine("SELECT wc.workcentername,wc.workcenterid  FROM workcenter wc")
        Return DatabaseHelper.Query_ReturnDatTable(strsql.ToString())
    End Function

    ''' <summary>
    ''' 获取文档集信息 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetDocumentSetInfoDT() As DataTable Implements IBusiness.uLMSEmployeeIBusiness.GetDocumentSetInfoDT
        Dim strsql As String =
            <string>
                SELECT db.documentname,dt.documentid FROM DOCUMENT dt 
                LEFT JOIN documentbase db ON db.documentbaseid = dt.documentbaseid
            </string>
        Return DatabaseHelper.Query_ReturnDatTable(strsql)
    End Function

    ''' <summary>
    ''' 获取班组信息 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetTeamInfoDT() As DataTable Implements IBusiness.uLMSEmployeeIBusiness.GetTeamInfoDT
        Dim strsql As String =
            <string>
                SELECT t.teamname,t.teamid FROM team t 
            </string>
        Return DatabaseHelper.Query_ReturnDatTable(strsql)
    End Function

    ''' <summary>
    ''' 获取班信息 
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetShiftInfoDT() As DataTable Implements IBusiness.uLMSEmployeeIBusiness.GetShiftInfoDT
        Dim strsql As String =
            <string>
                SELECT st.shiftname,st.shiftid FROM shift st
            </string>
        Return DatabaseHelper.Query_ReturnDatTable(strsql)
    End Function


End Class
